/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.applis.demo.forms;

import opiam.admin.applis.demo.beans.Department;

import org.apache.struts.action.ActionForm;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;


/**
 * This class describes the department formBean.
 */
public class DepartmentForm extends ActionForm implements Serializable
{
    /** Department object. */
    private Department dp = new Department();
    
    /** Description multivalued field. */
    private List descrp = null;


    /**
     * Creates a new DepartmentForm object.
     */
    public DepartmentForm()
    {
    }

    /**
     * Gets the department.
     *
     * @return The department.
     */
    public Department getDepartment()
    {
        return dp;
    }

    /**
     * Sets the department.
     *
     * @param department  The department to set.
     */
    public void setDepartment(Department department)
    {
        this.dp = department;
    }

    /**
     * Reset all the value of the object.
     */
    public void reset()
    {
        dp = null;
    }
    
    /**
     * Gets the description(multi-valued attribute).
     * Used by the jsp page.
     *
     * @return the description.
     */
    public String getDescrp()
    {
        StringBuffer sb = new StringBuffer();

        if ((descrp != null) && (descrp.size() > 0))
        {
            for (int i = 0; i < descrp.size(); i++)
            {
                sb.append((String) descrp.get(i));
                sb.append("\n");
            }

            return sb.toString();
        }

        return "";
    }

    /**
     * Sets the dscription(multi-valued attribute).
     * Used by the jsp page.
     *
     * @param descrp  The description to set.
     */
    public void setDescrp(String adescrp)
    {
        if ((adescrp != null) && (adescrp.trim().length() > 0))
        {
            StringTokenizer stk = new StringTokenizer(adescrp, "\n");
            descrp = new ArrayList();

            while (stk.hasMoreTokens())
            {
                descrp.add(stk.nextToken());
            }
        }
        else
        {
            descrp = null;
        }
    }

    /**
     * Gets the description (multi-valued attribute).
     * Used by the person bean.
     */
    public Collection getDescription()
    {
        return descrp;
    }

    /**
     * Sets the description(multi-valued attribute).
     * Used by the person bean.
     *
     * @param ldescrp  The description to set.
     */
    public void setDescription(Collection ldescrp)
    {
        this.descrp = new ArrayList();

        if ((ldescrp != null) && (ldescrp.size() > 0))
        {
            this.descrp.addAll(ldescrp);
        }
    }
    
}
